#include "stdafx.h"
#include "ConfigureRebot.h"
#include "ManagerRebot.h"

BW_SINGLETON_STORAGE(ConfigureRebot);
ConfigureRebot::ConfigureRebot(void)
{
	ManagerRebot::GetInstance()->RegisterRebot(string("ConfigureRebot"),this);
	objName = "ConfigureRebot";
	//m_lpszClassName = "ConfigureRebot";
	objType = E_OBJECT_TYPE::CONFIGER_ROBOT;
}


ConfigureRebot::~ConfigureRebot(void)
{
}

void ConfigureRebot::Updata()
{
	XObject::Updata();
}

unsigned int ConfigureRebot::ProcFun()
{
	return 0;
}

unsigned int ConfigureRebot::Init()
{
	printf("ConfigureRebot: start: Load config.ini\n");
	/*
	<server>
	 <ipport>172.17.1.66:3009</ipport>	
	</server>
	<thread>
	 <threadcount>10</threadcount>
	 <clientcount>1000</clientcount>
	</thread>

	*/
	char buff[1024*8] ={0};
	char tmp[64]={0};
	FILE* fp = fopen("config.ini", "r");
	if(fp != NULL)
	{
		int ret = fread(buff, 1, 1024*8, fp);
		fclose(fp);

		char* pb = strstr(buff, "<ipport>");
		char* pe = strstr(pb, ":");
		memcpy(tmp, pb+8, pe-pb-8);
		strServerIP = tmp;
		memset(tmp, 0, 64);

		pb = strstr(pb, "</ipport>");
		memcpy(tmp, pe+1, pb-pe-1);
		dwServerPort = atoi(tmp);

		pb = strstr(buff, "<threadcount>");
		pe = strstr(pb, "</threadcount>");
		memset(tmp, 0, 64);
		memcpy(tmp, pb+13, pe-pb-13);
		iThreadCount = atoi(tmp);

		pb = strstr(buff, "<clientcount>");
		pe = strstr(pb, "</clientcount>");
		memset(tmp, 0, 64);
		memcpy(tmp, pb+13, pe-pb-13);
		iRobotCount = atoi(tmp);

		pb = strstr(buff, "<clientIP>");
		pe = strstr(pb, "</clientIP>");
		memset(tmp, 0, 64);
		memcpy(tmp, pb+10, pe-pb-10);
		strClientIP = tmp;

		pb = strstr(buff, "<clientArea>");
		pe = strstr(pb, "</clientArea>");
		memset(tmp, 0, 64);
		memcpy(tmp, pb+12, pe-pb-12);
		strArea = tmp;

		pb = strstr(buff, "<clientFirstName>");
		pe = strstr(pb, "</clientFirstName>");
		memset(tmp, 0, 64);
		memcpy(tmp, pb+17, pe-pb-17);
		strClientFirstName = tmp;

		pb = strstr(buff, "<clientBeginName>");
		pe = strstr(pb, "</clientBeginName>");
		memset(tmp, 0, 64);
		memcpy(tmp, pb+17, pe-pb-17);
		strClientBeginName = tmp;
		iClientNameID = atoi(tmp);
	}
	else
	{
		strServerIP="172.17.1.66";
		dwServerPort=3009;
		iThreadCount = 10;
		iRobotCount	 = 1000;
	}
	return 0;
}